define(['jquery','api','user','pages/index/model','Vue','text!pages/order/detail.html','util'],function($,api,user,model,Vue,tpl,util){
	var view,
	    vm,
	    timer1,
	    timer2;
	var controller={
	   init:function (opensn) {
	       var str,
	           data;
	       if(!user.checkLogin())return;
	       if(model.code==null){
	   	   		data=api.getGoods();
	   	   		if(!data||(data.errorcode&&data.errorcode!=0)||data.retcode!='0')return;
	   	   		model.addGoods(data);
	       }
	       api.initFooter(1);
	       util.setTitle('持仓单详情');	       
	       this.bind();
           this.loadOrder(opensn);
	    },
	    bind:function(){
	       $('#pages').append('<div id="orderDetail"></div>');
	       if(vm){
	          vm.show=true;
	       }else{
	          vm=new Vue({
	          	  el:'#orderDetail',
	              data:{
	                 show:true,
	                 cfg:util.cfg.noPercent,
	                 closePrice:'--',
	                 fpl:'--',
	                 order:false,
	                 showClose:false,
	                 showStop:false,
	                 closeOrder:false
	              },
	              filters:{
	                 lowHigh:util.lowHigh,
	                 priceFormat:function(v,mindecimal){
	                 	return v?util.priceFormat(mindecimal,v):'';
                      }
	              },
	              methods:{
	                
	              },
	              template:tpl
	          })
	       }
	    },
	    loadOrder:function(id){
	    	var that=this,
	    	    order=api.getOrder();
	       if(order&&order.opensn==id){
	       	   vm.order=order;
   			}else{
   			   util.msg('数据加载失败，返回上一页！')
   			   setTimeout(function(){history.go(-1);},500);
   			}    	    	   
	    },
        onRouteChange:function(){
	    	vm.show=false
	    	if(timer1)clearTimeout(timer1);
	    }
	}
    return controller;     
})